import { CURRENT_TOKEN } from '@/components/Authorized/renderAuthorize';
import request from '@/utils/request';
import URLS from './APIUrlDefine';

export async function GetAssetList(data: any, type: number) {
  return request(`${URLS.GET_ASSET_LIST}/${data.current}/${data.pageSize}?type=${type}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  });
}

export async function CreateNewAsset(data: any) {
  return request(`${URLS.CREATE_NEW_ASSET}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data),
  });
}

/**
 * 删除指定的资源
 */
export async function DeleteAsset(data:any) {
  return request(`${URLS.DELETE_ASSET}/${data}`, {
    method: 'DELETE',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data
  });
 }

export async function ChangeAssetState() { }
